package com.youyi.yyviewsdklibrary.Dialog.core;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.youyi.yyviewsdklibrary.Dialog.animator.PopupAnimator;
import com.youyi.yyviewsdklibrary.Dialog.animator.TranslateAnimator;
import com.youyi.yyviewsdklibrary.Dialog.enums.PopupAnimation;
import com.youyi.yyviewsdklibrary.Dialog.enums.PopupStatus;
import com.youyi.yyviewsdklibrary.Dialog.interfaces.OnViewBack;
import com.youyi.yyviewsdklibrary.Dialog.util.KeyboardUtils;
import com.youyi.yyviewsdklibrary.Dialog.util.XPopupUtils;
import com.youyi.yyviewsdklibrary.Dialog.widget.SmartDragLayout;
import com.lkx.liandianqinew.R;

public class BottomPopupView extends BasePopupView {
    protected SmartDragLayout bottomPopupContainer = ((SmartDragLayout) findViewById(R.id.bottomPopupContainer));
    private View mContentView;
    protected OnViewBack mOnViewBack;
    protected int realLayout;
    private TranslateAnimator translateAnimator;

    public BottomPopupView(Context context) {
        super(context);
    }

    /* access modifiers changed from: protected */
    @Override // com.youyi.yyviewsdklibrary.Dialog.core.BasePopupView
    public void onCreate() {
        super.onCreate();
        OnViewBack onViewBack = this.mOnViewBack;
        if (onViewBack != null) {
            onViewBack.result(new XDialog(this, null), this.mContentView);
        }
    }

    public BottomPopupView(Context context, int i, OnViewBack onViewBack) {
        super(context);
        this.realLayout = i;
        this.mOnViewBack = onViewBack;
    }

    /* access modifiers changed from: protected */
    @Override // com.youyi.yyviewsdklibrary.Dialog.core.BasePopupView
    public int getImplLayoutId() {
        return this.realLayout;
    }

    /* access modifiers changed from: protected */
    public void addInnerContent() {
        View inflate = LayoutInflater.from(getContext()).inflate(getImplLayoutId(), (ViewGroup) this.bottomPopupContainer, false);
        this.mContentView = inflate;
        this.bottomPopupContainer.addView(inflate);
    }

    /* access modifiers changed from: protected */
    @Override // com.youyi.yyviewsdklibrary.Dialog.core.BasePopupView
    public final int getInnerLayoutId() {
        return R.layout._xpopup_bottom_popup_view;
    }

    /* access modifiers changed from: protected */
    @Override // com.youyi.yyviewsdklibrary.Dialog.core.BasePopupView
    public void initPopupContent() {
        super.initPopupContent();
        if (this.bottomPopupContainer.getChildCount() == 0) {
            addInnerContent();
        }
        this.bottomPopupContainer.setDuration(getAnimationDuration());
        this.bottomPopupContainer.enableDrag(this.popupInfo.enableDrag.booleanValue());
        if (this.popupInfo.enableDrag.booleanValue()) {
            this.popupInfo.popupAnimation = null;
            getPopupImplView().setTranslationX((float) this.popupInfo.offsetX);
            getPopupImplView().setTranslationY((float) this.popupInfo.offsetY);
        } else {
            getPopupContentView().setTranslationX((float) this.popupInfo.offsetX);
            getPopupContentView().setTranslationY((float) this.popupInfo.offsetY);
        }
        this.bottomPopupContainer.dismissOnTouchOutside(this.popupInfo.isDismissOnTouchOutside.booleanValue());
        this.bottomPopupContainer.isThreeDrag(this.popupInfo.isThreeDrag);
        XPopupUtils.applyPopupSize((ViewGroup) getPopupContentView(), getMaxWidth(), getMaxHeight(), getPopupWidth(), getPopupHeight(), null);
        this.bottomPopupContainer.setOnCloseListener(new SmartDragLayout.OnCloseListener() {
            /* class com.youyi.yyviewsdklibrary.Dialog.core.BottomPopupView.AnonymousClass1 */

            @Override // com.youyi.yyviewsdklibrary.Dialog.widget.SmartDragLayout.OnCloseListener
            public void onOpen() {
            }

            @Override // com.youyi.yyviewsdklibrary.Dialog.widget.SmartDragLayout.OnCloseListener
            public void onClose() {
                BottomPopupView.this.beforeDismiss();
                if (!(BottomPopupView.this.popupInfo == null || BottomPopupView.this.popupInfo.xPopupCallback == null)) {
                    BottomPopupView.this.popupInfo.xPopupCallback.beforeDismiss(BottomPopupView.this);
                }
                BottomPopupView.this.doAfterDismiss();
            }

            @Override // com.youyi.yyviewsdklibrary.Dialog.widget.SmartDragLayout.OnCloseListener
            public void onDrag(int i, float f, boolean z) {
                if (BottomPopupView.this.popupInfo != null) {
                    if (BottomPopupView.this.popupInfo.xPopupCallback != null) {
                        BottomPopupView.this.popupInfo.xPopupCallback.onDrag(BottomPopupView.this, i, f, z);
                    }
                    if (BottomPopupView.this.popupInfo.hasShadowBg.booleanValue() && !BottomPopupView.this.popupInfo.hasBlurBg.booleanValue()) {
                        BottomPopupView bottomPopupView = BottomPopupView.this;
                        bottomPopupView.setBackgroundColor(bottomPopupView.shadowBgAnimator.calculateBgColor(f));
                    }
                }
            }
        });
        this.bottomPopupContainer.setOnClickListener(new OnClickListener() {
            /* class com.youyi.yyviewsdklibrary.Dialog.core.BottomPopupView.AnonymousClass2 */

            public void onClick(View view) {
                if (BottomPopupView.this.popupInfo != null) {
                    if (BottomPopupView.this.popupInfo.xPopupCallback != null) {
                        BottomPopupView.this.popupInfo.xPopupCallback.onClickOutside(BottomPopupView.this);
                    }
                    if (BottomPopupView.this.popupInfo.isDismissOnTouchOutside != null) {
                        BottomPopupView.this.dismiss();
                    }
                }
            }
        });
    }

    @Override // com.youyi.yyviewsdklibrary.Dialog.core.BasePopupView
    public void doShowAnimation() {
        if (this.popupInfo != null) {
            if (this.popupInfo.enableDrag.booleanValue()) {
                if (this.popupInfo.hasBlurBg.booleanValue() && this.blurAnimator != null) {
                    this.blurAnimator.animateShow();
                }
                this.bottomPopupContainer.open();
                return;
            }
            super.doShowAnimation();
        }
    }

    @Override // com.youyi.yyviewsdklibrary.Dialog.core.BasePopupView
    public void doDismissAnimation() {
        if (this.popupInfo != null) {
            if (this.popupInfo.enableDrag.booleanValue()) {
                if (this.popupInfo.hasBlurBg.booleanValue() && this.blurAnimator != null) {
                    this.blurAnimator.animateDismiss();
                }
                this.bottomPopupContainer.close();
                return;
            }
            super.doDismissAnimation();
        }
    }

    /* access modifiers changed from: protected */
    @Override // com.youyi.yyviewsdklibrary.Dialog.core.BasePopupView
    public void doAfterDismiss() {
        if (this.popupInfo != null) {
            if (this.popupInfo.enableDrag.booleanValue()) {
                if (this.popupInfo.autoOpenSoftInput.booleanValue()) {
                    KeyboardUtils.hideSoftInput(this);
                }
                this.handler.removeCallbacks(this.doAfterDismissTask);
                this.handler.postDelayed(this.doAfterDismissTask, 0);
                return;
            }
            super.doAfterDismiss();
        }
    }

    /* access modifiers changed from: protected */
    @Override // com.youyi.yyviewsdklibrary.Dialog.core.BasePopupView
    public PopupAnimator getPopupAnimator() {
        if (this.popupInfo == null) {
            return null;
        }
        if (this.translateAnimator == null) {
            this.translateAnimator = new TranslateAnimator(getPopupContentView(), getAnimationDuration(), PopupAnimation.TranslateFromBottom);
        }
        if (this.popupInfo.enableDrag.booleanValue()) {
            return null;
        }
        return this.translateAnimator;
    }

    @Override // com.youyi.yyviewsdklibrary.Dialog.core.BasePopupView
    public void dismiss() {
        if (this.popupInfo != null) {
            if (!this.popupInfo.enableDrag.booleanValue()) {
                super.dismiss();
            } else if (this.popupStatus != PopupStatus.Dismissing) {
                this.popupStatus = PopupStatus.Dismissing;
                if (this.popupInfo.autoOpenSoftInput.booleanValue()) {
                    KeyboardUtils.hideSoftInput(this);
                }
                clearFocus();
                this.bottomPopupContainer.close();
            }
        }
    }

    /* access modifiers changed from: protected */
    @Override // com.youyi.yyviewsdklibrary.Dialog.core.BasePopupView
    public int getMaxWidth() {
        if (this.popupInfo.maxWidth == 0) {
            return XPopupUtils.getAppWidth(getContext());
        }
        return this.popupInfo.maxWidth;
    }

    /* access modifiers changed from: protected */
    @Override // com.youyi.yyviewsdklibrary.Dialog.core.BasePopupView
    public void onDetachedFromWindow() {
        if (!(this.popupInfo == null || this.popupInfo.enableDrag.booleanValue() || this.translateAnimator == null)) {
            getPopupContentView().setTranslationX(this.translateAnimator.startTranslationX);
            getPopupContentView().setTranslationY(this.translateAnimator.startTranslationY);
            this.translateAnimator.hasInit = true;
        }
        super.onDetachedFromWindow();
    }
}
